// Copyright (C) 1997-2002 Alias|Wavefront,
// a division of Silicon Graphics Limited.
//
// The information in this file is provided for the exclusive use of the
// licensees of Alias|Wavefront.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias|Wavefront license agreement, without fee.
//
// ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
//
//
//  Alias|Wavefront Script File
//  MODIFY THIS AT YOUR OWN RISK
//
//  Creation Date:  Dec 3, 1998
//
//  Procedure Name:
//      performPolySetToFaceNormal
//
//  Description:
//      Perform an operation that set selected vertex or vertex-face normals
//		to their face normals
//         
//

proc setOptionVars (int $forceFactorySettings)
{			   
	if ($forceFactorySettings || !`optionVar -exists polySetToFaceNormalUserNormal`)
		optionVar -intValue polySetToFaceNormalUserNormal 1;
}

global proc performPolySetToFaceNormalSetup (string $parent, int $forceFactorySettings)
{
	setOptionVars($forceFactorySettings);
	setParent $parent;

	int $ival;

	$ival = `optionVar -q polySetToFaceNormalUserNormal`;
	checkBoxGrp -e -v1 $ival polySetToFaceNormalUserNormal;	
}

global proc performPolySetToFaceNormalCallback (string $parent, int $doIt)
{
	setParent $parent;

	optionVar -intValue polySetToFaceNormalUserNormal
		`checkBoxGrp -q -v1 polySetToFaceNormalUserNormal`;

	if ($doIt) {
		performPolySetToFaceNormal 0;
		addToRecentCommandQueue "performPolySetToFaceNormal 0" "PolySetToFaceNormal";
	}
}

proc polySetToFaceNormalOptions()
{
	string $commandName = "performPolySetToFaceNormal";
	string $callback = ($commandName + "Callback");
	string $setup = ($commandName + "Setup");
	   
	string $layout = getOptionBox();
	setParent $layout;
	setUITemplate -pushTemplate DefaultTemplate;
	waitCursor -state 1;
	tabLayout -scr true -tv false;
	
	string $parent = `columnLayout -adjustableColumn 1`;

	checkBoxGrp -l1 "Set User Normal"
		polySetToFaceNormalUserNormal;

	setParent ..;

	waitCursor -state 0;
	setUITemplate -popTemplate;
	   
	string $applyBtn = getOptionBoxApplyBtn();
	button -edit -label "Set To Face"
	       -command ($callback + " " + $parent + " " + 1)
		$applyBtn;

	string $saveBtn = getOptionBoxSaveBtn();
	button -edit 
		-command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
		$saveBtn;

	string $resetBtn = getOptionBoxResetBtn();
	button -edit 
		-command ($setup + " " + $parent + " " + 1)
		$resetBtn;
			 
	setOptionBoxTitle("Polygon Set To Face Normal Options");

	setOptionBoxHelpTag( "NormalsSetToFace" );

	eval (($setup + " " + $parent + " " + 0));      
	showOptionBox();
}

global proc string performPolySetToFaceNormal (int $option)
{
	string $cmd="";
	switch ($option) {

	  case 1: polySetToFaceNormalOptions; 
		// Just the option box
		break;
		
	  default:
		setOptionVars(false);

		int $val1 = `optionVar -q polySetToFaceNormalUserNormal`;

		if ($val1)
			$cmd = ("polySetToFaceNormal -setUserNormal ");
		else
			$cmd = ("polySetToFaceNormal ");

		if ($option == 0)
			evalEcho $cmd;
		break;
	}
	return $cmd;
}





